var app=app||{};

var UserView=Backbone.View.extend({
	tagName:"tr",
	template:_.template($("#user-template").html()),
	events:{
		"click button":"deleteUserHandle",
		"dblclick input":"activeHandle",
		"keypress":"confirmUpdateHandle"
	},
	render:function(){
		this.$el.html(this.template(this.model.toJSON()));
		return this;
	},
	deleteUserHandle:function(){
		this.model.destroy();
		this.$el.remove();
	},
	activeHandle:function(){
		this.$("input").attr("disabled",false);
	},
	confirmUpdateHandle:function(event){
		if(event.which==13){
			this.$("input").attr("disabled",true);
			var uname=this.$("input:first").val();
			var age=this.$("input:nth(1)").val();
			this.model.set("uname",uname);
			this.model.set("age",age);
			this.model.save();
		}
	}
});
app.UserView=UserView;